import datetime
import random
from function_tool import time_format_transform

import clickhouse_connect

connect_info = {
    'port': 8123,
    'host': '192.168.104.243',
    'username': 'default',
    'password': 'bwda2025',
    'database': 'lap_test'
}

client = clickhouse_connect.get_client(**connect_info)
column_list = ['id', 'ctime', 'dev_ip', 'way', 'org',
               'mark', 'key', 'data', 'raw', 'obj_code', 'log_from', 'op_time', 'sdc_err_code', 'sdc_err_msg',
               'bwd_create_time']
insert_data = []
table = 'ods_sdc_raw_log_local'
for i in range(100000):
    sid = str(random.randint(10 ** 14, 10 ** 16))
    bwd_create_time = datetime.datetime.now()
    ctime = datetime.datetime.strftime(bwd_create_time, '%Y-%m-%d %H:%M:%S')
    dev_ip = '192.168.2.102'
    way = 'login'
    org = '保旺达-组织部'
    mark = '1'
    skey = 'login'
    sdata = '{"username": "admin", "password": "admin"}'
    raw = '{"username": "admin", "password": "admin"}'
    obj_code = 'login'
    log_from = '4A_login'
    op_time = datetime.datetime.now()
    sdc_err_code = '1001'
    sdc_err_msg = '解析失败'
    insert_data.append(
        [sid, ctime, dev_ip, way, org, mark, skey, sdata, raw, obj_code, log_from, op_time, sdc_err_code, sdc_err_msg,
         bwd_create_time])
client.insert(table, insert_data, column_names=column_list)
client.close()
